﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EZCRS.HCMS.DataAcl;
using EZCRS.HCMS.Bll.baseinfo;
using EZCRS.HCMS.Web;
using EZCRS.HCMS.Entity;

namespace EZCRS.HCMS.Web.manage.hotel
{
    public partial class hotel_new : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckModule(53);
            //必须选择集团
            if (base.BasGroupId == 0)
                Response.Write(CFun.AlertMeg("必选选择一个集团！","back",""));

            if (!Page.IsPostBack)
            {
                #region
                CFun.SetListControl(ddlTimezone, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.TimeZone(), "CCT");
                CFun.SetListControl(ddlStars, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.StarRate(), "");
                CFun.SetListControl(ddlDiamond, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.DiamondRate(), "");
                CFun.SetListControl(ddlCheckin, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.DayHour(), "");
                CFun.SetListControl(ddlLatecheckin, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.DayHour(), "");
                CFun.SetListControl(ddlCheckout, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.DayHour(), "");
                CFun.SetListControl(ddlkeep, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.DayHour(), "");
                
                CFun.SetListControl(rblforeign, DataAcl.Common.YesOrNo(), "0");
                //CFun.SetListControl(rblhonest, DataAcl.Common.YesOrNo(), "0");
                CFun.SetListControl(rblpms, DataAcl.Common.YesOrNo(), "0");
                CFun.SetListControl(rblHot, DataAcl.Common.YesOrNo(), "0");
                CFun.SetListControl(rblOnTop, DataAcl.Common.YesOrNo(), "0");


                CFun.SetListControl(ddlCountry, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.HCountry(), "CN");

                CFun.SetListControl(ddlPropType, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.HProptype(), "HOT");

                ddlCountry.Attributes.Add("onchange", "javascript:initprovince();");
                #endregion

                //初始化酒店修改
                if (base.BasHotelId > 0)
                {
                    //修改酒店
                    HCRS_Hotel _hotel = new SqlClient.sql_hcrs_hotel().getitem(base.BasHotelId);
                    if (_hotel != null)
                    {
                        binddata(_hotel);

                        if (labStatus.Text == "inactive")
                        {
                            offdate.Visible = true;
                            offremark.Visible = true;
                            Button1.Text = "上线";
                            getactive();
                        }
                        else
                        {
                            Button1.Text = "下线";
                            offdate.Visible = false;
                            offremark.Visible = false;
                        }
                    }
                    else
                        base.ClientScript.RegisterClientScriptBlock(typeof(string), "alertmsg", CFun.AlertMeg("酒店信息查询出错，请稍候再试！", "non", ""));
                }
                else
                {
                    //判断用户是否有新增权限
                    if (true)
                    {
                        btnsave.Text = "新增";
                        txtTitle.ReadOnly = false;
                        txtpid.ReadOnly = false;
                    }
                    else
                    {
                        Response.Write(CFun.AlertMeg("没有新增酒店的权限！", "back", ""));
                        Response.End();
                    }
                    ccc.Text = "<script language=javascript>initprovince();</script>";
                }

                txtDateOpened.Attributes.Add("onclick", "event.cancelBubble=true;showCalendarTA('txtDateOpened',false,'txtDateOpened','txtDateOpened',null);");
                txtDateOpened.Attributes.Add("onblur", "if(!chkdate(this.value))this.value='yyyy-MM-dd';");

                txtDaterenovated.Attributes.Add("onclick", "event.cancelBubble=true;showCalendarTA('txtDaterenovated',false,'txtDaterenovated','txtDaterenovated',null);");
                txtDaterenovated.Attributes.Add("onblur", "if(!chkdate(this.value))this.value='yyyy-MM-dd';");
            }
        }

        private void binddata(HCRS_Hotel _hotel)
        {
            EZCRS.HCMS.Bll.CFun.bindpagedata<HCRS_Hotel>(this, _hotel);

            ccc.Text= "<script language=javascript>inithotelzone('" + _hotel.Country + "','" + _hotel.Provinceid.ToString() + "','" + _hotel.Cityid.ToString() + "','" + _hotel.Districtid.ToString() + "','"+_hotel.Commercialid.ToString()+"');</script>";
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            HCRS_Hotel _hotel = new HCRS_Hotel();
            _hotel = EZCRS.HCMS.Bll.CFun.getpagedata<HCRS_Hotel>(_hotel, this);
            _hotel.Id = Convert.ToInt32(hidId.Value);
            _hotel.GroupID = base.BasGroupId;
            _hotel.Cityid = (Request.Params["selcity"] != "") ? Convert.ToInt32(Request.Params["selcity"]) : 0;
            _hotel.Commercialid = (Request.Params["selCommercial"] != "") ? Convert.ToInt32(Request.Params["selCommercial"]) : 0;
            _hotel.Districtid = (Request.Params["seldistrict"] != "") ? Convert.ToInt32(Request.Params["seldistrict"]) : 0;
            _hotel.Country = ddlCountry.SelectedValue;
            _hotel.Provinceid = (Request.Params["selprovince"] != "") ? Convert.ToInt32(Request.Params["selprovince"]) : 0;
            _hotel.UpdateTime = DateTime.Now;

            if (_hotel.pid > 0)
            {
                if (new SqlClient.sql_hcrs_hotel().insertorupdate(_hotel))
                    Response.Write(CFun.AlertMeg(Resources.Site.SystemModifySuccess, "", "hotel_new.aspx"));
                else
                    Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strstatus = "active";
            if (labStatus.Text == "active")
                strstatus = "inactive";
            if(new Bllh_activelog().changestatus(base.BasPropertyId,strstatus,txtoffremark.Text,base.BasUserId))
                Page.ClientScript.RegisterClientScriptBlock(typeof(String), "scuress", CFun.AlertMeg(Resources.Site.SystemModifySuccess, "", "hotel_new.aspx"));
            else
                Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
        }

        private void getactive()
        {
            if (txtpid.Text != "")
            {
                HCRS_Activelog _log = new Bllh_activelog().getlastbypid(base.BasPropertyId);
                if (_log != null)
                {
                    laboffremark.Text = _log.offremark;
                    offlinedate.Text = _log.offdate.ToString();
                }
            }
        }
    }
}
